<?php
require('config.php');

        $user_id=$_REQUEST['user_id'];
        $to_user_id=$_REQUEST['to_user_id'];
        $pan=$_REQUEST['pan'];
        $sql="select * from ".$oto."_favorites where `userId`='$user_id' and `targetId`='$to_user_id' and `favoriteType`='2'";
    	$result=$db->query($sql);
    	while($row=$result->fetch_assoc()){
    		$isGuanzhu[]=$row;//将取得的所有数据赋值给person_info数组
    	}
        $time=date('Y-m-d H:i:s');
        if($pan=='1')
        {
                if(!isset($isGuanzhu))
                {
                        $sql="INSERT INTO ".$oto."_favorites (`userId`,`targetId`,`favoriteType`,`createTime`) VALUES ('$user_id','$to_user_id','2','$time')";
                        $result=$db->query($sql);
                }
                else
                {
                      $result=true;
                }

        }
        else if($pan=='2')
        {
                if(!isset($isGuanzhu))
                {
                      $result=false;  
                }
                else
                {
                        $result=true;
                }
        }
        else if($pan=='0')
        {
                $sql="DELETE FROM ".$oto."_favorites where `userId`='$user_id' and `targetId`='$to_user_id' and `favoriteType`='2'";
                $result=$db->query($sql);
        }
	echo json_encode($result);
?>